package com.company.project.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.company.project.common.utils.DataResult;

import com.company.project.entity.ProjectVoteEntity;
import com.company.project.service.ProjectVoteService;
import com.company.project.vo.req.PageParam;

/**
 * 项目投票关联表
 *
 * @author ls
 * @email *****@mail.com
 * @date 2021-03-31 10:24:43
 */
@Controller
@RequestMapping("/")
public class ProjectVoteController {
    @Autowired
    private ProjectVoteService projectVoteService;

    //---------------------------前端方法---------------------------
    @SuppressWarnings({ "rawtypes", "unchecked" })
	@ApiOperation(value = "查询项目投票排行")
	@PostMapping("project/vote/rank")
	@ResponseBody
    public DataResult getProjectVoteRank(@RequestBody PageParam param) {
    	Page page = new Page(param.getPageIndex(), param.getPageSize());
    	
    	LambdaQueryWrapper<ProjectVoteEntity> queryWrapper = Wrappers.lambdaQuery();
    	queryWrapper.orderByAsc(ProjectVoteEntity::getRank);
        //查询条件示例
        //queryWrapper.eq(ProjectVoteEntity::getId, projectVote.getId());
        IPage<ProjectVoteEntity> iPage = projectVoteService.page(page, queryWrapper);
    	
    	return DataResult.success(iPage);
    }
    
    
    //---------------------------后端方法---------------------------
    /**
    * 跳转到页面
    */
    @GetMapping("/index/projectVote")
    public String projectVote() {
        return "projectvote/list";
        }

    @ApiOperation(value = "新增")
    @PostMapping("projectVote/add")
    @RequiresPermissions("projectVote:add")
    @ResponseBody
    public DataResult add(@RequestBody ProjectVoteEntity projectVote){
        projectVoteService.save(projectVote);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("projectVote/delete")
    @RequiresPermissions("projectVote:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        projectVoteService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("projectVote/update")
    @RequiresPermissions("projectVote:update")
    @ResponseBody
    public DataResult update(@RequestBody ProjectVoteEntity projectVote){
        projectVoteService.updateById(projectVote);
        return DataResult.success();
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
	@ApiOperation(value = "查询分页数据")
    @PostMapping("projectVote/listByPage")
    @RequiresPermissions("projectVote:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody ProjectVoteEntity projectVote){
        Page page = new Page(projectVote.getPage(), projectVote.getLimit());
        LambdaQueryWrapper<ProjectVoteEntity> queryWrapper = Wrappers.lambdaQuery();
        //查询条件示例
        //queryWrapper.eq(ProjectVoteEntity::getId, projectVote.getId());
        IPage<ProjectVoteEntity> iPage = projectVoteService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

}
